package com.ruoyi.project.mobile.goodsclass;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.common.utils.R;
import com.ruoyi.common.utils.RFactory;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.system.goods.goods.domain.GoodsGoods;
import com.ruoyi.project.system.goods.goods.enums.GoodsStatus;
import com.ruoyi.project.system.goods.goods.service.IGoodsGoodsService;
import com.ruoyi.project.system.goodsclass.domain.GoodsClass;
import com.ruoyi.project.system.goodsclass.service.IGoodsClassService;

/**
 * 功能：
 *
 * @author：dell
 * @create：2020/6/21 21:17
 * @version：2020 Version：1.0
 * @company：老屋新房 Created with IntelliJ IDEA
 */
@RestController
@RequestMapping("/api/class")
public class ApiClassController extends BaseController {

	@Autowired
	private IGoodsClassService goodsClassService;
	@Autowired
	private IGoodsGoodsService goodsGoodsService;

	/**
	 * 查询一级分类列表
	 * @param uid
	 * @return
	 */
	@GetMapping
	private R findAll(@RequestParam String uid){
		return RFactory.generateR(this.goodsClassService.findApiList());
	}

	/**
	 * 插叙分类下的二级分类
	 * @param id
	 * @return
	 */
	@GetMapping("/son")
	private R findClassSon(@RequestParam String id,@RequestParam String uid){
		GoodsClass goodsClass = new GoodsClass();
		goodsClass.setParentId(id);
		goodsClass.setStatus(0);
		return RFactory.generateR(this.goodsClassService.selectGoodsClassList(goodsClass));
	}

	/**
	 * 查询分类下的商品列表
	 * @param id
	 * @return
	 */
	@GetMapping("/goods")
	private R findGoodsList(@RequestParam String uid,@RequestParam String id){
		startPage();
		GoodsGoods goodsGoods = new GoodsGoods();
//		goodsGoods.setStatus(GoodsStatus.UP_SHELF.getValue());
		goodsGoods.setClassId(id);
		return RFactory.generateR(getDataTable(this.goodsGoodsService.findGoodsDtoList(goodsGoods)));
	}
}
